home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / misc1 / iv26_w30.zip / SOURCES / SUBJECT.C < prev    next >
C/C++ Source or Header  |  1980-01-03  |  2KB  |  88 lines

  1. /*
  2.  * Copyright (c) 1987, 1988, 1989 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and its
  5.  * documentation for any purpose is hereby granted without fee, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Stanford not be used in advertising or
  9.  * publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  Stanford makes no representations about
  11.  * the suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  20.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21.  */
  22.  
  23. /*
  24.  * Implementation of subject base class.
  25.  */
  26.  
  27. #include <InterViews/interactor.h>
  28. #include <InterViews/subject.h>
  29.  
  30. Subject::Subject() {
  31.     views = nil;
  32. }
  33.  
  34. Subject::~Subject() {
  35.     register ViewList* v, * next;
  36.  
  37.     for (v = views; v != nil; v = next) {
  38.     next = v->next;
  39.     delete v;
  40.     }
  41. }
  42.  
  43. void Subject::Attach(Interactor* i) {
  44.     ViewList* v = new ViewList;
  45.     v->element = i;
  46.     v->next = views;
  47.     views = v;
  48.     Reference();
  49. }
  50.  
  51. void Subject::Detach(Interactor* i) {
  52.     register ViewList* v, * prev;
  53.  
  54.     prev = nil;
  55.     for (v = views; v != nil; v = v->next) {
  56.     if (v->element == i) {
  57.         if (prev == nil) {
  58.         views = v->next;
  59.         } else {
  60.         prev->next = v->next;
  61.         }
  62.         delete v;
  63.         Unreference();
  64.         break;
  65.     }
  66.     prev = v;
  67.     }
  68. }
  69.  
  70. void Subject::all(InteractorItr& i) {
  71.     i.cur = views;
  72. }
  73.  
  74. void Subject::Notify() {
  75.     for (InteractorItr i(this); i.more(); i.next()) {
  76.     i.view()->Update();
  77.     }
  78. }
  79.  
  80. boolean Subject::IsView(Interactor* v) {
  81.     for (InteractorItr i(this); i.more(); i.next()) {
  82.     if (i.view() == v) {
  83.         return true;
  84.     }
  85.     }
  86.     return false;
  87. }
  88.